package com.tbsoft.trail.service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.tbsoft.trail.model.MergedOrder;
import com.tbsoft.trail.model.PurchaseOrder;

/**
 * @desc 订单合并处理service
 * 
 * @author lizhenhua
 * 
 */
public class OrderMergeService {
	/**
	 * @desc 根据订单list合并生成采购单
	 * @param orderLst
	 * @return
	 */
	public MergedOrder mergeOrder(List<PurchaseOrder> orderLst) {
		BigDecimal merged = new BigDecimal("0");

		BigDecimal temp = null;
		for (PurchaseOrder order : orderLst) {
			temp = new BigDecimal(order.getAmount());
			merged = merged.add(order.getPrice().multiply(temp));
		}
		MergedOrder mo = new MergedOrder();
		Date d = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		mo.setDescription(sdf.format(d) + " 订单");
		mo.setMergedValue(merged);
		return mo;
	}
}
